
function $(idStr){
	return document.getElementById?document.getElementById(idStr):document.all[idStr];
}

var nclick=0; var xx=[0,0]; var yy=[0,0];

function showPic(){
	SoftReset();
	if($('foto').value == ''){
		alert(str_choose_photo);
	} else {
		$('imgUpload').submit();
		$('im1').src=indicatorurl;
	}
}

function getResponse(iFrame){
	var d;
	if (iFrame.contentDocument) {
		d = iFrame.contentDocument; 
	} else if (iFrame.contentWindow) {
		d = iFrame.contentWindow.document;
	} else if (iFrame.document) {
		d = iFrame.document;
	} else {
		return null;
	}
	
	if (d.location.href == 'about:blank') {
		return null;
	}
	return d.body.innerHTML;
}

function uploadComplete(iFrame){
	var response = getResponse(iFrame);
	if(response==null || response.indexOf("ERROR:")==0){
		$('im1').src=blankeyesurl;
		$('foto').value="";
		if(response!=null && response.indexOf("ERROR:")==0) alert(str_error+response.substring(6));
	} else {
	    if(response.indexOf("Porno")==0){
		 if (confirm(str_porno_content)) {
		  $('im1').src=loadfotourl;
		  $('eyesimg').src=lefteyeurl;
		  //$('dival').innerHTML=str_choose_eye_right;
		  alert(str_choose_eye_right);
		  //dval.visibility="visible";
	     } else {
		  $('im1').src=blankeyesurl;
		  $('foto').value="";
	     }
	    }
	   else
	   {
	   	 $('im1').src=loadfotourl;
		 $('eyesimg').src=lefteyeurl;
		 alert(str_choose_eye_right);  
	   } 
	}
}

function myAlert(e){
	if (!e) e=window.event;
	if($('foto').value==''){
		alert(str_choose_photo);
		return false;
	}
	var index=nclick;
	nclick++;
	if (nclick<=2){
		if (e.clientX){
			xx[index]=e.clientX+document.body.scrollLeft+document.documentElement.scrollLeft-parseInt(divs.left);
			yy[index]=e.clientY+document.body.scrollTop+document.documentElement.scrollTop-parseInt(divs.top);
			sp[index].left=(e.clientX-3+document.body.scrollLeft+document.documentElement.scrollLeft)+"px";
			sp[index].top=(e.clientY-3+document.body.scrollTop+document.documentElement.scrollTop)+"px";
		} else if (e.offsetX){//old IE
			xx[index]=e.offsetX;
			yy[index]=e.offsetY;
			sp[index].left=(xx[index]-3+parseInt(divs.left))+"px";
			sp[index].top=(yy[index]-3+parseInt(divs.top))+"px";
		} else {
			alert(str_browser_unsupported);
			return false;
		}
		/*@cc_on
		sp[index].left = (parseInt(sp[index].left) - 1)+"px"; 
		sp[index].top = (parseInt(sp[index].top) - 1)+"px";
		@*/	
		sp[index].visibility="visible";

	    if (index==0){ alert(str_choose_eye_left); $('eyesimg').src=righteyeurl; return false;}
	    if (index==1){ $('eyesimg').src=blankeyesurl; alert(str_ok_or_clear);}
	} else {
		alert(str_ok_or_clear);
		return true;
	}
	return true;
}

function resetScript(){
SoftReset(); 
$('eyesimg').src=blankeyesurl; 
$('im1').src=blankeyesurl; 
$('imgUpload').reset(); 
$('imgCoords').reset(); 
return true;}

function SoftReset()
{
xx[0]=0; 
xx[1]=0; 
yy[0]=0; 
yy[1]=0; 
nclick=0; 
sp[0].visibility="hidden"; 
sp[1].visibility="hidden"; 
dval.visibility="hidden"; 
sp[0].left=0; 
sp[0].top=0; 
sp[1].left=0; 
sp[1].top=0; 
return true;}

function picPresent(ims){
if (ims==""){alert(str_press_browse); return false;}
else{ var tmpims=ims.toLowerCase();
    if((tmpims.indexOf(".gif")==-1)&&(tmpims.indexOf(".jpg")==-1)&&(tmpims.indexOf(".jpeg")==-1)){ alert(str_img_incorrect_format); return false;}
    else {return true;}
}}

function VeriForm(){
    if (!picPresent($('foto').value)) { return false; }
    if(nclick<1){ alert(str_choose_eye_right); return false; }
    if(nclick<2){ alert(str_choose_eye_left); return false; }
    if (xx[1]<xx[0]){ alert(str_eye_left_right_incorrect); resetScript(); return false; }

	var imgCoords = $('imgCoords');
    imgCoords.xr.value=xx[0]; imgCoords.xl.value=xx[1];
	imgCoords.yr.value=yy[0]; imgCoords.yl.value=yy[1];
	//inserted
	$('imgCoords').submit();
    //return true;
}
function myImgError(){
	alert("Error: could not upload image");
	resetScript();
}
